// 2140. 解决智力问题
// AC: https://leetcode.cn/problems/solving-questions-with-brainpower/submissions/617751804/

class Solution {
public:
    long long mostPoints(vector<vector<int>>& questions) {
        int n=questions.size();
        vector<long long> res(n,0);
        res[n-1]=questions[n-1][0];
        for(int i=n-2;i>=0;--i){
            int idex=questions[i][1]+i+1;
            res[i]=questions[i][0];
            if(idex<n){
                res[i]+=res[idex];
            }
            res[i]=max(res[i],res[i+1]);
        }
        return res[0];
    }
};